<?php

namespace App\Http\Middleware;

use App\Model\User;
use Closure;

class WechatBind
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if($user = \Auth::guard('wechat')->user()){

            if($user->number !== null){
                return $next($request);
            }
        }

        session(['targetUrl' => $request->url()]);

        return response()->view('errors.bind')->header('refresh', '1;url=' . url('user/bind'));
    }
}
